package 单例模式;

//1.懒汉式（线程不安全）
public class Singleton {
    private static Singleton uniqueInstance;

    private Singleton() {
    }

    public static Singleton getSingleton() {
        if (uniqueInstance == null) {
            uniqueInstance = new Singleton();
        }
        return uniqueInstance;
    }

    //2.饿汉式-线程安全
    private static Singleton uniqueInstance2 = new Singleton();

    //3.懒汉式-线程安全
    public static synchronized Singleton getUniqueInstance(){
        if(uniqueInstance==null){
            uniqueInstance=new Singleton();
        }
        return uniqueInstance;
    }
}
